package org.mineground.commands.player.admin;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.mineground.Main;
import org.mineground.PermissionNodes;

/**
 * @name ClearInventory.java
 * @author Daniel Koenen (2012)
 */
public class ClearInventory implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmnd, String string, String[] arguments) {
        Player player = (Player) sender;

	if (!player.hasPermission(PermissionNodes.PERMISSION_CLEARINV_COMMAND)) {
            return true;
        }
        
        if (arguments.length > 0) {
            if (!player.hasPermission(PermissionNodes.PERMISSION_CLEARINV_ALL_COMMAND)) {
                return true;
            }
            
            Player clearPlayer = Main.getInstance().getServer().getPlayer(arguments[0]);
            
            if (clearPlayer == null) {
                player.sendMessage(ChatColor.RED + "* Error: Invalid player.");
                return true;
            }
            
            clearPlayer.getInventory().clear();
            
            player.sendMessage(ChatColor.DARK_GREEN + clearPlayer.getName() + "'s inventory has been cleared.");
            clearPlayer.sendMessage(ChatColor.RED + "Your inventory has been cleared.");
            return true;
        }
        
        player.getInventory().clear();
        player.sendMessage(ChatColor.RED + "Your inventory has been cleared.");
        return true;
    }
}
